﻿using AutoMapper;
using FarmSmartSleep.Common.Domain;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Common.Infrastructure;
using MediatR;

namespace FarmSmartSleep.Organ.API.Application.Commands.EnterpriseCommands
{
    public class EnterpriseTypeHandler: IRequestHandler<EnterpriseTypeCommand, Result>
    {
        public IBaseRepository<Province> provinceRepository;
        public IBaseRepository<City> cityRepository;
        public IBaseRepository<County> countyRepository;
        public IMapper mapper;

        public EnterpriseTypeHandler(IBaseRepository<Province> provinceRepository, IMapper mapper, IBaseRepository<City> cityRepository, IBaseRepository<County> countyRepository)
        {
            this.provinceRepository = provinceRepository;
            this.cityRepository = cityRepository;
            this.countyRepository = countyRepository;
            this.mapper = mapper;
        }
        //省下拉框
        public Task<Result> Handle(EnterpriseTypeCommand request, CancellationToken cancellationToken)
        {
            Result result = new Result();
            result.Code = 1;
            result.Messege= "成功";
            var res= provinceRepository.GetAll().ToList();
            List< EnterpriseTypeListCommand> lists=new List<EnterpriseTypeListCommand>();
            foreach (var item in res)
            {
                var sf= mapper.Map<EnterpriseTypeListCommand>(item);
                lists.Add(sf);
            }
            result.Data = lists;
            return Task.FromResult(result);
        }

      
    }
}
